/**
 * @param {number} amount
 * @param {number[]} coins
 * @return {number}
 */
var change = function (amount, coins) {
    if (amount === 0) return 1

    let dp = new Array(coins.length).fill(0).map(val => new Array(amount + 1).fill(0))
    for (let i = 0; i < dp.length; i++) {
        dp[i][0]=1;
    }
    for (let j = 0; j < dp[0].length; j++) {
        if(j>=coins[0]){
            dp[0][j] = dp[0][j-coins[0]]
        }
    }

    console.log(dp);
    for (let i = 1; i < coins.length; i++) {
        for (let j = 1; j <= amount; j++) {
            if(j>=coins[i]){
                dp[i][j] = dp[i-1][j] + dp[i][j-coins[i]]
            }else{
                dp[i][j] = dp[i-1][j]
            }

        }

    }
    return dp[coins.length-1][amount]
};
let arr = [2, 1, 5]
change(5,arr)